<template>
  <ContentWrap>
    <!-- 搜索工作栏 -->
    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="酒店名称" prop="hotelName">
        <el-input
          v-model="queryParams.hotelName"
          placeholder="请输入酒店名称"
          clearable
          @keyup.enter="handleQuery"
          class="!w-240px"
        />
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
        <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column label="酒店名称" align="center" prop="hotelName" />
      <el-table-column label="酒店地址" align="center" prop="hotelAddress" />
      <el-table-column
        label="入住时间"
        align="center"
        prop="checkInTime"
        :formatter="dateFormatter"
        width="180px"
      />
      <el-table-column
        label="退房时间"
        align="center"
        prop="checkOutTime"
        :formatter="dateFormatter"
        width="180px"
      />
      <el-table-column label="房间号" align="center" prop="roomNo" width="70"/>
      <el-table-column label="入住名字" align="center" prop="checkInPersonName" width="110"/>
      <el-table-column label="联系电话" align="center" prop="checkInPersonPhone" width="110"/>

      <el-table-column label="同住人员" align="center" prop="checkInPersonName" width="110"/>
<!--      <el-table-column-->
<!--        label="创建时间"-->
<!--        align="center"-->
<!--        prop="createTime"-->
<!--        :formatter="dateFormatter"-->
<!--        width="180px"-->
<!--      />-->
<!--      <el-table-column label="操作" align="center" min-width="120px">-->
<!--        <template #default="scope">-->
<!--          <el-button-->
<!--            link-->
<!--            type="primary"-->
<!--            @click="openForm('update', scope.row.id)"-->
<!--            v-hasPermi="['member:hotel-record:update']"-->
<!--          >-->
<!--            编辑-->
<!--          </el-button>-->
<!--          <el-button-->
<!--            link-->
<!--            type="danger"-->
<!--            @click="handleDelete(scope.row.id)"-->
<!--            v-hasPermi="['member:hotel-record:delete']"-->
<!--          >-->
<!--            删除-->
<!--          </el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>

  <!-- 表单弹窗：添加/修改 -->
  <HotelRecordForm ref="formRef" @success="getList" />
</template>

<script setup lang="ts">
import { dateFormatter } from '@/utils/formatTime'
import { HotelRecordApi, HotelRecordVO } from '@/api/member/hotelrecord'
import HotelRecordForm from '@/views/member/hotelrecord/HotelRecordForm.vue'

/** 旅馆住宿 列表 */
defineOptions({ name: 'HotelRecord' })

const loading = ref(true) // 列表的加载中
const list = ref<HotelRecordVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数

const { personId } = defineProps({
  personId: {
    type: [String, Array], // 同时支持字符串和数组类型
    required: true
  }
})

const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  personId: personId,
  hotelName: undefined,
  hotelAddress: undefined,
  checkInTime: [],
  checkOutTime: [],
  roomNo: undefined,
  checkInPersonName: undefined,
  checkInPersonPhone: undefined,
  createTime: []
})
const queryFormRef = ref() // 搜索的表单

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await HotelRecordApi.getHotelRecordPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}

/** 添加/修改操作 */
const formRef = ref()

/** 初始化 **/
onMounted(() => {
  getList()
})
</script>
